package com.foreknow.mapping;

import com.foreknow.db.DBManager;

import java.util.HashMap;
import java.util.Map;

public class MappingFactory {
    private static MappingFactory mappingFactory = null;
    private Map<String,EntityMapping> maps = new HashMap<>();
    public static final String PERSON_MAPPING = "personMapping"; //常量
    public static final String EMP_MAPPING = "empMapping"; //常量
    public static final String ADMIN_MAPPING = "adminMapping"; //常量


    private MappingFactory(){
    }

    public static MappingFactory getInstance() {
        if (mappingFactory == null) {
            mappingFactory = new MappingFactory();
            //将xxxMapping对象保存到Map集合中
            mappingFactory.maps.put(PERSON_MAPPING,new PersonMapping());
            mappingFactory.maps.put(EMP_MAPPING,new EmpMapping());
            mappingFactory.maps.put(ADMIN_MAPPING,new AdminMapping());
        }
        return mappingFactory;
    }

    /**
     * 定义方法从Map集合中获取到某个对象
     */
    public EntityMapping getMapping(String key) {
        return maps.get(key);
    }
}
